#include<stdio.h>
#include<pthread.h>
#include<semaphore.h>
#include<time.h>

void cashier();
void manager();
void customer();
void clerk();

struct inspection{
	int passed;
  	sem_t *requested;
	sem_t *finished;
	sem_t *lock;
}INP;


sem_t * createSemaphore( const char * inName, const int inStartingCount )
{
      sem_t * semaphore = sem_open( inName, O_CREAT, 0644, inStartingCount );
      return semaphore;
}

int createRandom(int start,int range){
	srand((int)time(0));
	return rand()%range+start;
}

 int main(){
	pthread_t tCustomer[10];
	int numberoficecream;
	INP.requested = createSemaphore("inp.requested",0);
	INP.finished = createSemaphore("inp.finished",0);
	INP.lock = createSemaphore("inp.lock",1);
	INP.passed = 0;
	for(int i=0;i<10;i++)
	{
		int numicecreate = createRandom(1,4);
		int ret = pthread_create(&tCustomer[i],NULL,(void*)customer);
		if(ret!=0){
			printf("create cutomer[%d] failed\n",i);
		}
	}
	int ret = pthread_create(&tCustomer[i],NULL,(void*)customer);
	if(ret !=0)
		printf("create cashier failed;");
	ret = pthread_create(&tCustomer[i],NULL,(void*)customer);
	if(ret!=0){
		printf("create cutomer[%d] failed\n",i);
	}
}
